package com.bayair.doctor.biz.im;

import android.view.View;
import com.bayair.doctor.R;
import com.bayair.doctor.base.component.BaseFragment;
import com.bayair.doctor.biz.im_helper.IMHelper;
import com.bayair.doctor.ui.chat.ChatActivity;
import com.tencent.qcloud.tim.uikit.modules.chat.base.ChatInfo;
import com.tencent.qcloud.tim.uikit.modules.contact.ContactLayout;

public class ContactFragment extends BaseFragment {

    private static final String TAG = ContactFragment.class.getSimpleName();
    private ContactLayout mContactLayout;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_im_contact;
    }

    @Override
    protected void initView() {
        initViews(getView());
    }

    @Override
    protected void initData() {
        refreshData();
    }

    @Override
    public void onVisible() {
        log("ContactFragment === onVisible");
        refreshData();
    }

    private void initViews(View view) {
        // 从布局文件中获取通讯录面板
        mContactLayout = view.findViewById(R.id.contact_layout);
        mContactLayout.getTitleBar().setVisibility(View.GONE);
        mContactLayout.getContactListView().setOnItemClickListener((position, contact) -> {
            ChatInfo chatInfo = IMHelper.getInstance().contactToChat(contact);
            ChatActivity.actionStart(chatInfo);
        });
        mContactLayout.getContactListView().setDataChangeListener(mData -> {
            log("更新本地联系人");
        });
    }

    private void refreshData() {
        // 通讯录面板的默认UI和交互初始化
        mContactLayout.initDefault();
    }
}
